__author__ = 'TANUKI'

# coding:utf-8
import time, sys
import public
import allure



#继承Base类
class iOSWalletPage():
    def IntoWallet(driver):
        try:
            with allure.step('关掉Coming Soon！'):
                time.sleep(3)
                public.comingsoon(driver)
            with allure.step('进入Wallet页面'):
                time.sleep(3)
                public.switchDealorWallet(driver,"Wallet")
                #driver.find_element_by_ios_predicate("label == \"Wallet\"")
            with allure.step('查看My Wallet页面中MyDeals'):
                time.sleep(5)
                public.xiafangzuohua(driver)
                time.sleep(3)
                public.xiafangzuohua(driver)
            with allure.step('点击See All查看所有订单显示'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"See All\" AND name == \"See All\" AND type == \"XCUIElementTypeButton\"").click()
                #label == "See All" AND name == "See All" AND type == "XCUIElementTypeButton"
            with allure.step('上滑查看页面数据是否正确'):
                time.sleep(3)
                public.iOSshanghua(driver)
            with allure.step('返回Wallet页面'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"black back\"").click()
                #label == "black back"
            with allure.step('进入Activity页面'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Activity\"").click()
            with allure.step('查看全部订单'):
                time.sleep(3)
                public.iOSshanghua(driver)
                time.sleep(3)
                public.iOSshanghua(driver)
                time.sleep(3)
                public.iOSshanghua(driver)
            pytest_TestResult = True

        except Exception as e:
            print ("My Wallet页面报错：",e)
            pytest_TestResult = False
        finally:
            return pytest_TestResult

    def DebitCardAdd(driver):
        try:
            with allure.step('关掉Coming Soon！'):
                time.sleep(3)
                public.comingsoon(driver)
            with allure.step('进入Wallet页面'):
                time.sleep(3)
                public.switchDealorWallet(driver,"Wallet")
            with allure.step('点击Add充值'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Add\" AND name == \"Add\" AND value == \"Add\"").click()
                #label == "Add" AND name == "Add" AND value == "Add"
            '''
            with allure.step('输入充值金额999'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("value == \"0.00\"").send_keys("999")
                #label == "Confirm Funding" AND name == "Confirm Funding" AND type == "XCUIElementTypeButton"
            with allure.step('测试$250金额按钮是否功能正常'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"$250\" AND name == \"$250\" AND type == \"XCUIElementTypeButton\"").click()
            with allure.step('测试$100金额按钮是否功能正常'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"$100\" AND name == \"$100\" AND type == \"XCUIElementTypeButton\"").click()
            with allure.step('测试$50金额按钮是否功能正常'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"$50\" AND name == \"$50\" AND type == \"XCUIElementTypeButton\"").click()
            with allure.step('测试$25金额按钮是否功能正常'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"$25\" AND name == \"$25\" AND type == \"XCUIElementTypeButton\"").click()
            '''
            with allure.step('测试$10金额按钮是否功能正常'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"$10\" AND name == \"$10\" AND type == \"XCUIElementTypeButton\"").click()
            with allure.step('点击Comfirm Funding'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Confirm Funding\" AND name == \"Confirm Funding\" AND type == \"XCUIElementTypeButton\"").click()
            with allure.step('点击Pay with a New Card or Bank Account'):
                time.sleep(10)
                driver.find_element_by_ios_predicate("label == \"Pay with a New Card or Bank Account\"").click()
            with allure.step('Choose Debit Card'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Debit Card\" AND name == \"Debit Card\" AND value == \"3\" AND type == \"XCUIElementTypeStaticText\"").click()


            with allure.step('输入Expiry date'):
                time.sleep(8)
                driver.find_element_by_xpath("//XCUIElementTypeTextField[@name=\"MM/YY\"]").send_keys("0230")
            with allure.step('输入Security code'):
                time.sleep(3)
                #driver.find_element_by_ios_predicate("label == \"CVV\" AND name == \"CVV\"").click()
                #driver.find_element_by_ios_predicate("label == \"CVV\" AND name == \"CVV\"").send_keys("100")
                driver.find_element_by_xpath("//XCUIElementTypeTextField[@name=\"CVV\"]").send_keys("100")

            with allure.step('输入DebitCard卡号'):
                time.sleep(3)
                driver.find_element_by_xpath("//XCUIElementTypeTextField[@name=\"Card number\"]").send_keys("4242424242424242")
            with allure.step('点击支付按钮'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"PAY $10.35\"").click()
            with allure.step('进入第三方3DS2 Challenge页面输入Hint:Checkout!'):
                time.sleep(15)
                driver.find_element_by_ios_predicate("value == \"Hint: Checkout1!\"").send_keys("Checkout1!")
            with allure.step('点击Continue'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Continue\"").click()
            with allure.step('绑卡充值完成，点击Done！'):
                time.sleep(8)
                driver.find_element_by_ios_predicate("label == \"Done\"").click()
            pytest_TestResult = True
        except Exception as e:
            print("绑定DebitCard测试报错：",e)
            pytest_TestResult = False
        finally:
            return pytest_TestResult


    def BankAccountAdd(driver):
        try:
            with allure.step('关掉Coming Soon！'):
                time.sleep(3)
                public.comingsoon(driver)
            with allure.step('进入Wallet页面'):
                time.sleep(3)
                public.switchDealorWallet(driver,"Wallet")
            with allure.step('点击Add充值'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Add\" AND name == \"Add\" AND value == \"Add\"").click()
                #label == "Add" AND name == "Add" AND value == "Add"
            with allure.step('测试$10金额按钮是否功能正常'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"$10\" AND name == \"$10\" AND type == \"XCUIElementTypeButton\"").click()
            with allure.step('点击Comfirm Funding'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Confirm Funding\" AND name == \"Confirm Funding\" AND type == \"XCUIElementTypeButton\"").click()
            with allure.step('点击Pay with a New Card or Bank Account'):
                time.sleep(10)
                driver.find_element_by_ios_predicate("label == \"Pay with a New Card or Bank Account\"").click()
            with allure.step('Choose Bank Account'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Bank Account\" AND name == \"Bank Account\" AND value == \"3\" AND type == \"XCUIElementTypeStaticText\"").click()
            with allure.step('Choose Secure Verification'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Secure Verification\"").click()
            with allure.step('跳转到第三方的Plaid页面，点击Continue'):
                time.sleep(15)
                driver.find_element_by_ios_predicate("label == \"Continue\"").click()
            with allure.step('输入Security code'):
                time.sleep(8)
                #label == "Chase www.chase.com"
                driver.find_element_by_ios_predicate("label == \"Chase www.chase.com\"").click()
            with allure.step('Enter your credentials输入Username'):
                time.sleep(8)
                driver.find_element_by_ios_predicate("type == \"XCUIElementTypeTextField\"").send_keys("user_good")
            with allure.step('输入Password'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("type == \"XCUIElementTypeSecureTextField\"").send_keys("pass_good")
            with allure.step('点击Submit提交数据'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Submit\"").click()
            with allure.step('选择账户中的支付卡片'):
                time.sleep(15)
                driver.find_element_by_ios_predicate("label == \"Plaid Checking, account ending in 0000, balance $100.00\"").click()
            with allure.step('点击Continue提交绑卡信息'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Continue\"").click()
            with allure.step('点击完成页面的Continue关闭PLAID页面'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Continue\"").click()
                time.sleep(20)

            pytest_TestResult = True
        except Exception as e:
            print("添加绑定Bank Account测试报错：",e)
            pytest_TestResult = False
        finally:
            return pytest_TestResult

    def BankAccountTopUp(driver):
        try:
            with allure.step('关掉Coming Soon！'):
                time.sleep(3)
                public.comingsoon(driver)
            with allure.step('进入Wallet页面'):
                time.sleep(3)
                public.switchDealorWallet(driver,"Wallet")
            with allure.step('点击Add充值'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Add\" AND name == \"Add\" AND value == \"Add\"").click()
                #label == "Add" AND name == "Add" AND value == "Add"
            with allure.step('测试$10金额按钮是否功能正常'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"$10\" AND name == \"$10\" AND type == \"XCUIElementTypeButton\"").click()
            with allure.step('点击Comfirm Funding'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Confirm Funding\" AND name == \"Confirm Funding\" AND type == \"XCUIElementTypeButton\"").click()
            with allure.step('点击Chase'):
                time.sleep(15)
                #读卡很慢，等时间长一些
                driver.find_element_by_ios_predicate("label == \"Chase\"").click()
            with allure.step('点击Review Payment'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Review Payment\"").click()
            with allure.step('点击Pay进行支付'):
                time.sleep(3)
                driver.find_element_by_ios_predicate("label == \"Pay\" AND name == \"Pay\" AND value == \"Pay\"").click()
            pytest_TestResult = True


            with allure.step('点击Done完成页面'):
                time.sleep(5)
                driver.find_element_by_ios_predicate("label == \"Done\"").click()




        except Exception as e:
            print("Bank Account充值报错：",e)
            pytest_TestResult = False
        finally:
            return pytest_TestResult